<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
    <head>
        <c:choose>
            <c:when test="${not empty place.id or not empty param.id}">
                <title>DriveNotes::Редактировать место</title>
            </c:when>
            <c:otherwise>
                <title>DriveNotes::Добавить место</title>
            </c:otherwise>
        </c:choose>

        <link href="css/style.css" rel="stylesheet" type="text/css"/>
        <script src="js/jquery.js"></script>
        <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
        <script>
            var map;
            var markers;
            var zoom = 15;

            OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {                
                defaultHandlerOptions: {
                    'single': true,
                    'double': false,
                    'pixelTolerance': 0,
                    'stopSingle': false,
                    'stopDouble': false
                },

                initialize: function(options) {
                    this.handlerOptions = OpenLayers.Util.extend(
                    {}, this.defaultHandlerOptions
                );
                    OpenLayers.Control.prototype.initialize.apply(
                    this, arguments
                ); 
                    this.handler = new OpenLayers.Handler.Click(
                    this, {
                        'click': this.trigger
                    }, this.handlerOptions
                );
                }, 

                trigger: function(e) {
                    var lonlat = map.getLonLatFromViewPortPx(e.xy);

                    markers.clearMarkers();
                    marker = new OpenLayers.Marker(lonlat);
                    markers.addMarker(marker);

                    lonlat = lonlat.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));

                    $("#lon").val(lonlat.lon);
                    $("#lat").val(lonlat.lat);
                }

            });

            $(function() {
                map = new OpenLayers.Map("map");
                map.addLayer(new OpenLayers.Layer.OSM());

                click = new OpenLayers.Control.Click();
                map.addControl(click);
                click.activate();

                markers = new OpenLayers.Layer.Markers("Markers");
                map.addLayer(markers);

                lon = $("#lon").val();
                lat = $("#lat").val();
                        
                if(lon != '' && lat != '') {
                    var lonLat = new OpenLayers.LonLat(lon, lat)
                    .transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
                    marker = new OpenLayers.Marker(lonLat);
                    markers.addMarker(marker);
                    map.setCenter (lonLat, zoom);
                } else {
                    map.zoomTo(1);
                }
            });
        </script>
    </head>
    <body>
        <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td>&nbsp;</td>
                <td width="750" valign="top">
                    <table width="750" height="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td height="1">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td valign="top" background="images/p1-bg.jpg" class="norepeat">
                                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td><img src="images/spacer.gif" alt="" width="1" height="46"/></td>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td width="1"><img src="images/spacer.gif" width="17" height="1"/></td>
                                                    <td width="1"><img src="images/logo.jpg" alt="" width="50" height="51"/></td>
                                                        <c:choose>    
                                                            <c:when test="${not empty place.id or not empty param.id}">
                                                            <td class="c_name">DriveNotes::Редактировать место</td>
                                                        </c:when>
                                                        <c:otherwise>
                                                            <td class="c_name">DriveNotes::Добавить место</td>
                                                        </c:otherwise>
                                                    </c:choose>
                                                </tr>
                                            </table>
                                        </td>
                                        <td width="1"><img src="images/p2.jpg" alt="" width="331" height="255"/></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td height="100%" valign="top"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td width="1" valign="top"><img src="images/spacer.gif" alt="" width="9" height="1"/></td>
                                        <td height="100%" valign="top"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                                                <tr>
                                                    <td background="images/menu-1-bg.gif" class="norepeat"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td width="1"><img src="images/menu-bullet.gif" alt="" width="36" height="30"/></td>
                                                                <td class="menu"><a href="controller?act=garage" class="menu_lnk">Гараж</a></td>
                                                            </tr>
                                                        </table></td>
                                                </tr>
                                                <tr>
                                                    <td><img src="images/menu-sep.gif" alt="" width="181" height="1"/></td>
                                                </tr>
                                                <tr>
                                                    <td background="images/menu-2-bg.gif" bgcolor="#3F3F3F" class="norepeat"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td width="1"><img src="images/menu-bullet.gif" alt="" width="36" height="30"/></td>
                                                                <td class="menu"><a href="controller?act=service" class="menu_lnk">Сервис</a></td>
                                                            </tr>
                                                        </table></td>
                                                </tr>
                                                <tr>
                                                    <td bgcolor="#3F3F3F"><img src="images/menu-sep.gif" alt="" width="181" height="1"/></td>
                                                </tr>
                                                <tr>
                                                    <td bgcolor="#3F3F3F"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td width="1"><img src="images/menu-bullet.gif" alt="" width="36" height="30"/></td>
                                                                <td class="menu"><a href="controller?act=filling" class="menu_lnk">Заправка</a></td>
                                                            </tr>
                                                        </table></td>
                                                </tr>
                                                <tr>
                                                    <td bgcolor="#3F3F3F"><img src="images/menu-sep.gif" alt="" width="181" height="1"/></td>
                                                </tr>
                                                <tr>
                                                    <td bgcolor="#3F3F3F"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td width="1"><img src="images/menu-bullet.gif" alt="" width="36" height="30"/></td>
                                                                <td class="menu"><a href="controller?act=notes" class="menu_lnk">Заметки</a></td>
                                                            </tr>
                                                        </table></td>
                                                </tr>
                                                <tr>
                                                    <td bgcolor="#3F3F3F"><img src="images/menu-sep.gif" alt="" width="181" height="1"/></td>
                                                </tr>
                                                <tr>
                                                    <td bgcolor="#3F3F3F"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td width="1"><img src="images/menu-bullet.gif" alt="" width="36" height="30"/></td>
                                                                <td class="menu"><a href="controller?act=places" class="menu_lnk">Места</a></td>
                                                            </tr>
                                                        </table></td>
                                                </tr>
                                                <tr>
                                                    <td bgcolor="#3F3F3F"><img src="images/menu-sep.gif" alt="" width="181" height="1"/></td>
                                                </tr>
                                                <tr>
                                                    <td bgcolor="#3F3F3F"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td width="1"><img src="images/menu-bullet.gif" alt="" width="36" height="30"/></td>
                                                                <td class="menu"><a href="controller?act=statistic" class="menu_lnk">Статистика</a></td>
                                                            </tr>
                                                        </table></td>
                                                </tr>
                                                <tr>
                                                    <td><img src="images/menu-sep.gif" alt="" width="181" height="1"/></td>
                                                </tr>

                                                <tr>
                                                    <td bgcolor="#3F3F3F"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td width="1"><img src="images/menu-bullet.gif" alt="" width="36" height="30"/></td>
                                                                <td class="menu"><a href="controller?act=logout" class="menu_lnk">Выход</a></td>
                                                            </tr>
                                                        </table></td>
                                                </tr>
                                                <tr>
                                                    <td><img src="images/menu-sep.gif" alt="" width="181" height="1"/></td>
                                                </tr>

                                                <tr>
                                                    <td height="100%" bgcolor="#3f3f3f">&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td background="images/menu-bot-bg.gif" class="bgx"><img src="images/menu-bot-bg.gif" width="1" height="97"/></td>
                                                </tr>
                                            </table>
                                        </td>
                                        <td width="1" valign="top">
                                            <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                                                <tr>
                                                    <td><img src="images/c-top.jpg" alt="" width="560" height="17"/></td>
                                                </tr>
                                                <tr>
                                                    <c:choose>    
                                                        <c:when test="${not empty place.id or not empty param.id}">
                                                            <td><h1>DriveNotes::Редактировать место</h1></td>
                                                        </c:when>
                                                        <c:otherwise>
                                                            <td><h1>DriveNotes::Добавить место</h1></td>
                                                        </c:otherwise>
                                                    </c:choose>

                                                </tr>
                                                <tr>
                                                    <td height="100%" class="body_txt">
                                                        <p>
                                                        <div id="map"></div><br/>
                                                        <c:if test="${not empty error}">
                                                            <p style="color:red;">Ошибка: проверьте правильность заполнения полей</p>
                                                        </c:if>
                                                        <c:choose>
                                                            <c:when test="${not empty error}">
                                                                <c:set var="placeProps" value="${param}"/>
                                                            </c:when>
                                                            <c:when test="${not empty place}">
                                                                <c:set var="placeProps" value="${place}"/>
                                                            </c:when>
                                                        </c:choose>
                                                        <form action="controller?act=editPlace&amp;subact=save" method="post">
                                                            <input type="hidden" name="id" value="${placeProps.id}"/>
                                                            <input type="hidden" name="lat" id="lat" value="${placeProps.lat}"/>
                                                            <input type="hidden" name="lon" id="lon" value="${placeProps.lon}"/>
                                                            <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                                                                <tr><td width="80">Название *: </td><td colspan="2"><input type="text" name="name" tabindex="1" class="input_field" value="${placeProps.name}" style="width:100%;"/></td></tr>
                                                                <tr><td colspan="3">Описание: </td></tr>
                                                                <tr><td colspan="3"><textarea name="note" rows="10" tabindex="2" class="input_field" style="width:100%;">${placeProps.description}</textarea></td></tr>
                                                                <tr><td colspan="3">&nbsp;</td></tr>
                                                                <tr><td colspan="2" style="text-align:left;color: red;">Поля помеченные * обязательны к заполнению</td><td style="text-align:right;" width="70"><input type="submit" class="submit_btn" tabindex="3" value="Сохранить"/></td></tr>
                                                            </table>
                                                        </form>
                                                        </p>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td height="1" background="images/bottom-bg.jpg" class="norepeat"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>

                                    </tr>
                                    <tr>
                                        <td class="bottom_addr">2011 DriveNotes (c).</td>
                                    </tr>
                                </table></td>
                        </tr>
                    </table>
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>
    </body>
</html>

